<template>
<div class="main">
  <!-- 头部导航栏 -->
  <head-component :noBack="false"  title="提现"/>
  <div class="btcT_con">
    <div class="list f32 col_66"><span>提现类型</span><select name="" id="" class="col_33 f32" v-model="type"><option value="团队奖收益">团队奖收益</option><option value="佣金收益">佣金收益</option></select><img
      src="@/common/icon/down.png" alt=""></div>
    <div class="list f32 col_66"><span>支付宝账号</span><input type="text" placeholder='请输入收款账号'  class="col_33 f32" v-model="num"></div>
    <div class="list f32 col_66"><span>提现金额</span><input type="text" placeholder='请输入提现金额'  class="col_33 f32" v-model="money"><p @click="getTot()">全部</p></div>
    <div style="overflow:hidden;"><p  class="f32 col_99" style="float:left;">可提现：{{total}}元</p><p class="f32 col_99" style="float:right;">手续费:{{userInfo.charge}}</p></div>
    <div class="f30 col_99" style="margin-top:0.3rem">预计到账时间:&nbsp;
      <span>{{daoTime}}</span>
    </div>
  </div>
  <div class="global_btn" @click="withdrawSure()">提现</div>
</div>
</template>

<script>
import headComponent from '@/components/layout/head'
export default {
    name: "withdraw.vue",
    data(){
      return{
        userInfo:{},
        num:'',
        money:'',
        total:0,
        type:'团队奖收益',
        cate:1,
        m_rz:0,
        daoTime:'daoTime'
      }
    },
    created(){
      var $this = this;
      $this.getUserInfo();
      if($this.cate== 1 ){
        $this.total = $this.userInfo.m_money1
      }else{
        $this.total = $this.userInfo.m_money2
      }
    },
    methods:{
        //  个人信息
        getUserInfo(){
          var $this = this;
          var data = {u_id: localStorage.getItem('uid'),token:localStorage.getItem('token')};
          $this.$axios.post('index.php?m=user&c=index',data)
            .then((res) => {
              if(res.data.code == 1){
                $this.userInfo = res.data.user;
                $this.total = res.data.user.m_money1;
                $this.m_rz = res.data.user.m_rz;
              }else{
                $this.$router.push('/login');
              }
            });
          // 预计到账时间
          var date = new Date();
          var year = date.getFullYear();
          var month = date.getMonth() + 1;
          var day = date.getDate()+1;
          if(month < 10) {
            month = "0" + month;
          }
          if(day < 10) {
            day = "0" + day;
          }
          $this.daoTime = year + '-' + month + '-' + day
        },
      getTot(){
        var $this = this;
        $this.money =  $this.total;
      },
      withdrawSure(){
        let $this = this;

          console.log($this.daoTime)
          // if($this.m_rz == 2){
              if(!$this.num){
                this.$toast({
                  message: '请输入收款账号',
                  duration: 800
                })
                return
              }else if(!$this.money){
                this.$toast({
                  message: '请输入提现金额',
                  duration: 800
                })
                return
              }else if($this.money < 10){
                this.$toast({
                  message: '最少提现10元',
                  duration: 800
                })
                return
              } else if($this.money > $this.total){
                this.$toast({
                  message: '最多可提现'+$this.total,
                  duration: 800
                })
                return
              }else{
                var req = {u_id: localStorage.getItem('uid'),token:localStorage.getItem('token'),cate:$this.cate,num:$this.num,money:$this.money};
                $this.$axios.post('index.php?m=user&c=tixian',req)
                  .then((res) => {
                    if(res.data.code == 1){
                      this.$toast({
                        message: res.data.msg,
                        duration: 800,
                        onClose: ()=>{
                          this.$router.go(-1);
                        }})
                    }else{
                      this.$toast({
                        message: '请先登录',
                        duration: 800,
                        onClose: ()=>{
                          $this.$router.push('/login');
                        }
                      })
                    }
                  });
              }
          // }else if($this.m_rz == 0 || $this.m_rz == 3){
          //   $this.$toast({
          //     message: '请先实名认证',
          //     duration: 800,
          //     onClose: ()=> {
          //       $this.$router.push('/renzheng');
          //     }
          //   })
          // }else{
          //   $this.$toast({
          //     message: '实名认证审核中',
          //     duration: 800,
          //   })
          // }
        }
    },
    watch:{
      type(){
        var $this = this;
        $this.money = '';
        if($this.type=='团队奖收益'){
          $this.total = $this.userInfo.m_money1;
          $this.cate = 1;
        }else{
          $this.total = $this.userInfo.m_money2;
          $this.cate = 2;
        }
      }
    },
    components: {
      headComponent
    },
}
</script>

<style  scoped lang="less">
  .layout-head{border-bottom: 0.02rem solid #f5f5f5;}
  .btcT_con{
      width: 90%;
    margin: 1.733rem auto 0;
    .list{
      width: 100%;
      height: 1.3rem;
      line-height: 1.3rem;
      margin-bottom: 0.5333rem;
      overflow: hidden;
      border-radius: 0.16rem;
      box-shadow:0px 0px 14px #e9e9e9;
      img{float: right;height: 0.42rem;width: 0.42rem;margin-right: 0.46rem;margin-top: 0.4rem;}
      span{float: left;margin-left: 0.26rem;width: 2.2rem;}
      select{float: left;height: 100%;width: 62.7%;text-align-last: left;}
      input{float: left;height: 100%;}
      p{color: #4e4e4e;line-height: 1.3rem;float: right;margin-right: 0.46rem;}
    }
  }
  .global_btn{width: 92%;margin: 0.8rem auto 0;}
</style>
